package com.just.bz_back.controller.user;

import com.just.bz_back.config.CheckRole;
import com.just.bz_back.model.Repair;
import com.just.bz_back.model.RepairAdminDescription;
import com.just.bz_back.model.RepairUserDescription;
import com.just.bz_back.model.RepairWithBLOBs;
import com.just.bz_back.model.dto.JsonData;
import com.just.bz_back.service.RepairService;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import reactor.util.annotation.Nullable;

import javax.annotation.Resource;

/**
 * @author : baibaiwucahng
 * @date : 2019/8/31  15:51
 */

@RestController
@RequestMapping("/api/v1/user/repair")
public class RepairController {

    @Resource
    private RepairService repairService;

    /**
     * 创建维修表单
     * @param repair
     * @return
     */
    @RequestMapping(value = "/create",method = RequestMethod.POST)
    public JsonData createRepair(@RequestBody RepairWithBLOBs repair)
    {
       if (repairService.CreateRepair(repair)==0)
       {
           return JsonData.buildSuccess("","填报成功！");
       }
       return JsonData.buildError("服务器异常！");
    }


    @RequestMapping(value = "/listuser",method = RequestMethod.POST)
    public JsonData ListUser(@RequestBody RepairUserDescription repairUserDescription)
    {
        return JsonData.buildSuccess(repairService.ListUser(repairUserDescription),0);
    }

    @RequestMapping(value = "/listadmin",method = RequestMethod.POST)
    public JsonData ListAdmin(@RequestBody RepairAdminDescription repairAdminDescription)
    {
        return JsonData.buildSuccess(repairService.ListAdmin(repairAdminDescription),0);
    }

    @CheckRole(role = "user",roleId = 1)
    @RequestMapping(value = "/listrepair",method = RequestMethod.POST)
    public JsonData ListRepair(@RequestBody @Nullable Repair repair)
    {
        return JsonData.buildSuccess(repairService.ListRepair(repair));
    }

}
